package com.ruhaly.demo01.common;

import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component //注入依赖
@Aspect
public aspect TestAspect {
    @Pointcut("execution(* com.ruhaly.demo01.service.UserServiceImpl.*(..))")
    public void logAop() {
        System.out.println("TestAspect");
    }


    @Before("logAop() && args(name,pwd)")
    public void logBefore(String name, String pwd) {
        System.out.println(name + pwd + "前置通知Before-TestAspect");
    }

    @After("logAop() && args(name,pwd)")
    public void logAfter(String name, String pwd) {
        System.out.println(name + pwd + "后置通知After-TestAspect");
    }

    @AfterReturning("logAop()")
    public void logAfterReturning() {
        System.out.println("返回通知AfterReturning-TestAspect");
    }

    @AfterThrowing("logAop()")
    public void logAfterThrow() {
        System.out.println("异常通知AfterThrowing-TestAspect");
    }
}
